const {
    resolve
} = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'built.js',
        path: resolve(__dirname, 'build')
    },
    module: {
        rules: [{
            test: /\.less$/,
            use: [
                'style-loader',
                'css-loader',
                'less-loader'
            ]
        }, {
            //默认处理不了html中img
            test: /\.(jpg|png|gif)$/,
            loader: 'url-loader',
            options: {
                //图片小于8kb会转为base64
                limit: 8 * 1024,
                //问题：因为url-loader默认使用es6模块化解析，而html-loader引入图片是common.js
                //解析是会出问题：[object Module]
                //解决：关闭url-loader的es6模块化，使用commonjs解析
                esModule: false,
                name: '[hash:10].[ext]'
            }
        }, {
            test: /\.html$/,
            //处理html文件的img图片（负责引入img，从而能被url-loader进行处理）
            loader: 'html-loader',
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html'
        })
    ],
    mode: 'development'
}